package mapper;

import com.wl.mybatis.entity.Goods;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface GoodsMapper {
    @Select("<script>" +
            " select * from goods\n" +
            "       <where>\n" +
            "           <if test=\"id != null\">\n" +
            "               and id = #{id}\n" +
            "           </if>\n" +
            "\n" +
            "           <if test=\"name != null\">\n" +
            "               and name = #{name}\n" +
            "           </if>\n" +
            "\n" +
            "           <if test=\"nums != null\">\n" +
            "               and nums >= #{nums}\n" +
            "           </if>\n" +
            "\n" +
            "           <if test=\"bigNum != null\">\n" +
            "               and bigNum &lt;= #{bigNum}\n" +
            "           </if>\n" +
            "       </where>" +
            "</script>")
    List<Goods> select(Goods goods);

    @Update("<script>" +
            "update goods set\n" +
            "        <set>\n" +
            "            <if test=\"name != null\">\n" +
            "                name = #{name},\n" +
            "            </if>\n" +
            "            <if test=\"name != null\">\n" +
            "                type = #{type},\n" +
            "            </if>\n" +
            "            <if test=\"nums != null\">\n" +
            "                nums = #{nums},\n" +
            "            </if>\n" +
            "            <if test=\"price != null\">\n" +
            "                price = #{price},\n" +
            "            </if>\n" +
            "            <if test=\"state != null\">\n" +
            "                state = #{state},\n" +
            "            </if>\n" +
            "        </set>" +
            "</script>")
    List<Goods> select(GoodsEX goods);

    void update(Goods goods);

    @Update("update goods set name = #{name},type = #{type}," +
            "nums = #{nums},price = #{price},state = #{state}," +
            "where id = #{id}")
    void updateAll(Goods goods);

    @Select("select * from goods where id = #{id}")
    Goods selectById(int id);

    List<Goods> selecByName(@Param("name") String name,
                            @Param("op") int op);

    List<Goods> selectByIds(@Param("ids") List<Integer> ids);

    List<Goods> selectByType(@Param("type") String type,
                             @Param("role") String role,
                             @Param("buy") Boolean buy,
                             @Param("sort") String sort);

    List<Map<String,Object>> selectSql(@Param("sql") String sql);
}


